@extends('admin.base')
@section('css')
<link rel="stylesheet" href="/css/sweetalert/sweetalert.css"/>
@parent

@stop



@section('content')

<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>图文消息列表</h2>
        <ol class="breadcrumb">
            <li>
                <a href="{{route('/')}}">主页</a>
            </li>

            <li>
                <strong>图文消息列表</strong>
            </li>
        </ol>
    </div>
    <div class="col-lg-2">

    </div>
</div>
<div class="wrapper wrapper-content">
    <div class="row animated fadeInRight">
        <div class="col-md-4">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>最新图文</h5>
                </div>
                <div>

                    <div class="ibox-content no-padding border-left-right">
                        <img alt="image"  class="img-responsive" style="width: 343px;height: 228px" src="{{$new_news[0]['thumb_pic']}}">
                        <h4 style="padding: 5px 20px"><strong>{{$new_news[0]['title']}}</strong></h4>
                    </div>

                    <div class="ibox-content profile-content">

                        @foreach($new_news as $k=>$firstitem)
                        @if($k != 0)
                        <div class="feed-element">
                            <a href="profile.html#" class="pull-right">
                                <img alt="image" class="img-circle" src="{{$firstitem['thumb_pic']}}">
                            </a>
                            <div class="media-body ">
                                <small class="text-muted">{{$firstitem['title']}}</small>
                            </div>
                        </div>
                        @endif
                        @endforeach

                        <div class="user-button">
                            <div class="row">
                                <div class="col-md-6">
                                    <button type="button" class="btn btn-primary btn-sm btn-block edit-news"><i class="fa fa-pencil "></i> 编辑</button>
                                </div>
                                <div class="col-md-6">
                                    <button type="button" class="btn btn-danger btn-sm btn-block del-news" data-mediaid="{{$new_news[0]['media_id']}}"><i class="fa fa-trash"></i> 删除</button>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
        <div class="col-md-8">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>所有图文</h5>

                </div>
                <div class="ibox-content">

                    <div>
                        <div class="feed-activity-list">
                            @foreach($mediaIdList as $news)
                            <div class="feed-element">
                                @foreach($news as $k=>$item)
                                @if($k==0)
                                <a href="javascript:void(0);" class="pull-left">
                                    <img alt="{{$item['title']}}" class="img-circle" src="{{$item['thumb_pic']}}">
                                </a>
                                @endif
                                @endforeach
                                <div class="media-body ">
                                    @foreach($news as $k=>$item)
                                    @if($k == 0)
                                    <small class="pull-right text-navy">{{date('Y-m-d',$item['update_time'])}}</small>
                                    <strong>{{$item['title']}}</strong>
                                    @else
                                    <div class="actions" >
                                        <a href="javascript:void(0);" class="pull-left" style="margin-right: 10px;">
                                            <img alt="{{$item['title']}}" class="img-circle" src="{{$item['thumb_pic']}}">
                                        </a>
                                    </div>
                                    @endif
                                    @endforeach
                                    <div class="pull-right">

                                        <a class="btn btn-xs btn-white edit-news"><i class="fa fa-pencil"></i> 编辑</a>
                                        <a class="btn btn-xs btn-danger del-news" data-mediaid="{{$item['media_id']}}"><i class="fa fa-trash"></i> 删除</a>
                                    </div>
                                </div>
                            </div>
                            @endforeach


                        </div>

                        <?php echo $page->render();?>
                    </div>

                </div>
            </div>

        </div>
    </div>
</div>
@stop

@section('script')
@parent
<!--<script src="/js/sweetalert/sweetalert.min.js"></script>-->
<script>
    // 图文标题提示
    $('.actions').find('img').on('mouseover', function() {
        layer.tips($(this).attr('alt'), $(this), {tips:[1]});
    });

    // 编辑
    $('.edit-news').on('click', function() {
        swal('该功能稍后开放哦！');
    });

    // 删除
    $('.del-news').on('click', function() {
        var $mediaId = $(this).data('mediaid');
        console.log($mediaId);
        swal({
                title: "不要冲动",
                text: "你确定要删除这条图文消息吗？",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定!",
                cancelButtonText: "取消",
                closeOnConfirm: false,
                showLoaderOnConfirm: true
            },
            function(){
                $.ajax({
                    url : "{{route('news.destroy')}}",
                    type: 'DELETE',
                    data:{'mediaid':$mediaId},
                    success: function(data) {
                        if(data.code==2000) {
                            swal("成功!请点下刷新按钮~", data.message, "success");
                        }else {
                            swal("失败!", data.message, "error");
                        }
                    }
                });

            }
        );
    });
</script>
@stop
